package com.ly.talent.controller;

import java.util.List;

import com.ly.common.core.domain.model.LoginUser;
import com.ly.common.utils.ServletUtils;
import com.ly.framework.web.service.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ly.common.annotation.Log;
import com.ly.common.core.controller.BaseController;
import com.ly.common.core.domain.AjaxResult;
import com.ly.common.enums.BusinessType;
import com.ly.talent.domain.TalentBaseInfo;
import com.ly.talent.service.ITalentBaseInfoService;
import com.ly.common.utils.poi.ExcelUtil;
import com.ly.common.core.page.TableDataInfo;

/**
 * 人才引进基本信息Controller
 * 
 * @author sfli
 * @date 2021-02-01
 */
@RestController
@RequestMapping("/talent/talentBaseInfo")
public class TalentBaseInfoController extends BaseController
{
    @Autowired
    private ITalentBaseInfoService talentBaseInfoService;
    @Autowired
    private TokenService           tokenService;
    /**
     * 查询人才引进基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('talent:talentBaseInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(TalentBaseInfo talentBaseInfo)
    {
        startPage();
        List<TalentBaseInfo> list = talentBaseInfoService.selectTalentBaseInfoList(talentBaseInfo);
        return getDataTable(list);
    }

    /**
     * 导出人才引进基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('talent:talentBaseInfo:export')")
    @Log(title = "人才引进基本信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TalentBaseInfo talentBaseInfo)
    {
        List<TalentBaseInfo> list = talentBaseInfoService.selectTalentBaseInfoList(talentBaseInfo);
        ExcelUtil<TalentBaseInfo> util = new ExcelUtil<TalentBaseInfo>(TalentBaseInfo.class);
        return util.exportExcel(list, "人才信息列表");
    }

    /**
     * 获取人才引进基本信息详细信息
     */
    @GetMapping(value = "/{talentBaseInfoId}")
    public AjaxResult getInfo(@PathVariable("talentBaseInfoId") Long talentBaseInfoId)
    {
        return AjaxResult.success(talentBaseInfoService.selectTalentBaseInfoById(talentBaseInfoId));
    }

    /**
     * 新增人才引进基本信息
     */
    @Log(title = "人才引进基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TalentBaseInfo talentBaseInfo)
    {
        //小程序用户id
        String openId = tokenService.getWxOpenId(ServletUtils.getRequest());
        talentBaseInfo.setCreateBy(openId);
        talentBaseInfo.getTalentDetail().setCreateBy(openId);
        talentBaseInfoService.insertTalentBaseInfo(talentBaseInfo);
        return AjaxResult.success(talentBaseInfo);
    }

    /**
     * 修改人才引进基本信息
     */
    //@ApiOperation("修改人才引进基本信息")
    @PreAuthorize("@ss.hasPermi('talent:talentBaseInfo:edit')")
    @Log(title = "人才引进基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TalentBaseInfo talentBaseInfo)
    {
        return toAjax(talentBaseInfoService.updateTalentBaseInfo(talentBaseInfo));
    }

    /**
     * 删除人才引进基本信息
     */
    //@ApiOperation("删除人才引进基本信息")
    @PreAuthorize("@ss.hasPermi('talent:talentBaseInfo:remove')")
    @Log(title = "人才引进基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{talentBaseInfoIds}")
    public AjaxResult remove(@PathVariable Long[] talentBaseInfoIds)
    {
        return toAjax(talentBaseInfoService.deleteTalentBaseInfoByIds(talentBaseInfoIds));
    }
    /**
     * 审核通过
     */
    @PreAuthorize("@ss.hasPermi('talent:talentBaseInfo:edit')")
    @Log(title = "人才引进待审核信息审核通过", businessType = BusinessType.UPDATE)
    @PutMapping(value = "audit/yes/{talentBaseInfoId}")
    public AjaxResult auditYes(@PathVariable("talentBaseInfoId") Long talentBaseInfoId)
    {
        TalentBaseInfo talentBaseInfo = talentBaseInfoService.selectTalentBaseInfoById(talentBaseInfoId);
        talentBaseInfo.setResult("1");
        return toAjax(talentBaseInfoService.updateTalentBaseInfo(talentBaseInfo));
    }

    /**
     * 审核不通过
     */
    //@ApiOperation("修改人才引进基本信息")
    @PreAuthorize("@ss.hasPermi('talent:talentBaseInfo:edit')")
    @Log(title = "人才引进待审核信息审核不通过", businessType = BusinessType.UPDATE)
    @PutMapping(value = "audit/no/{talentBaseInfoId}")
    public AjaxResult auditNo(@PathVariable("talentBaseInfoId") Long talentBaseInfoId)
    {
        TalentBaseInfo talentBaseInfo = talentBaseInfoService.selectTalentBaseInfoById(talentBaseInfoId);
        talentBaseInfo.setResult("2");
        return toAjax(talentBaseInfoService.updateTalentBaseInfo(talentBaseInfo));
    }
}
